package thread;

/**
 * 使用匿名内部类创建线程
 */
public class ThreadDemo3 {
    public static void main(String[] args) {
        //第一种；继承thread并重写run方法
        Thread t1 = new Thread(){
            @Override
            public void run() {
                System.out.println("hello world");
            }
        };
        t1.start();

        //创建第二种;实现runnable接口并重写run方法
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("hello world");
            }
        };
        Thread t2 = new Thread(r1);
        t2.start();

        //第三种：lambda表达式
        Thread t3 = new Thread(()-> {
            for (int i = 0; i <1000 ; i++) {
                System.out.println("hello world");
            }
        });
        t3.start();
    }
}
